$(function(){
	
	var detailId=queryString('updateId');
	var flowId=queryString('flowId');
	//请求数据详情
	YuXi.Updates.requestDetail(detailId);

	YuXi.Updates.getInformationFlow(detailId);

	YuXi.Updates.init(
		detailId,
		flowId,
		"toEvaluate.jsp",//要返回跳转的页面
		23,//meunId
		"InfoEvaluation/addEvaluate.do"//提交接口
		);
	
	$("#goback").click(function(){	
		window.history.back();
	})

	//修改模态框确认按钮
	$("#update").click(function(){
		YuXi.Updates.requestUpdate();//调用修改数据方法
		$("#updateModal").modal('hide');
	})
//确认修改按钮
	$("#requestUpdate").click(function(){
		var pId=[];
   		var pName=[];
		 var text=$("#commit-text").text();
		 //可见人
		 var str="";
		$(".seePeople").find(".select-data-user").each(function(){
			pId.push($(this).attr("data-id"));
			pName.push($(this).html());
		})
		if(pId.length<=0)
		{
			 myTool.alert({		
					title:"提示",
					context:"请选择可见人",
					isMask:true,
					
				});
			 return false;
		}

		 if(text==null||text==""||text==str){
			 myTool.alert({		
					title:"提示",
					context:"评价内容不能为空",
					isMask:true,
					
				});
			
		 }else{
			 myTool.alert({		
					title:"提示",
					context:"是否确认评价?",
					isMask:true,
					callback:function(){
						inputCondition(text,pId,pName);
					}
				});
		 }
		 
		
		

	})
	
	function inputCondition(message,personId,personName){
			  peopleId=personId.join(",");//参与人
    		  peopleName=personName.join(",");
			  var url="InfoEvaluation/addEvaluate.do";
			  var args={id:detailId,text:message,peopleId:peopleId,peopleName:peopleName};
			
			  YuXi.util.get(url,args,function(data){
				  if(data.status)
				  {
					  myTool.alert({
							 title:"提示",
							 context:"评价成功"
						 });
					  setTimeout(function(){
						  window.location.href = 'toEvaluate.jsp?menuId=23';;
					  },500);
				  }
				  else
				  {		 
					  myTool.alert({
							 title:"提示",
							 context:"评价失败"
						 });
				  }
			  });
		  
	}
		
//正则取链接传来的数据
function queryString(key)
{
    var regex_str = "^.+\\?.*?\\b"+ key +"=(.*?)(?:(?=&)|$|#)"
    var regex = new RegExp(regex_str,"i");
    var url = window.location.toString();
    if(regex.test(url)) return RegExp.$1;
    return undefined;
}
function modal(msg,cont){
	myTool.alert({		
		title:msg,
		context:cont,
		isMask:true,
		callback:function(){}
	});
}

})